package StudyCode.summary.csv;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ParseCSVLine {
	public static String[] parseCSVLine(String line) {
		String[] field = new String[12];
		String temp = "";
		int index = 0;
		boolean hasQuotation = false;
		for (int i = 0; i < line.length(); i++) {
			Character currentChar = line.charAt(i);
			if (currentChar.equals('\"')) {
				hasQuotation = !hasQuotation;
			}
			if (currentChar.equals(',')) {
				if (!hasQuotation) {
					field[index] = temp;
					temp = "";
					index = index + 1;
				} else {
					temp = temp + line.charAt(i);
				}
			} else {
				temp = temp + line.charAt(i);
			}
			if (i == line.length() - 1) {
				field[index] = temp;
				temp = "";
				index = 0;
			}
		}
		return field;
	}
}
